$(function () {

//回车事件
    $(document).keydown(function(event){
        if(event.keyCode===13){
            login();
        }
    });

    $("#d_login").click( ()=> {
      login();
    });
    function login() {
        var userName=$("#username");
        var password=$("#password");
        //是否有空值;
        if(userName.val().trim().length==0  ){
            Notice_8("用户名不能为空");
            userName.parent().css("border","2px solid red ");
            userName.focus();
            return;
        }else if(password.val().trim().length==0) {
            userName.parent().css("border","2px solid #DDDDDD ");
            Notice_8("密码不能为空");
            password.parent().css("border","2px solid red ");
            password.focus();
            return;
        }
        //启动loading组件
        $(".d_body").mLoading("show");//显示loading组件
            userName.parent().css("border","2px solid #DDDDDD ");
            password.parent().css("border","2px solid #DDDDDD ");
            //执行登录操作
            $.ajax({
                type : "post",
                url : ctx+'/login',
                data : {
                    info:userName.val(),password:password.val()
                },
                success:(data)=>{
                    //关闭loading
                    $(".d_body").mLoading("hide");//显示loading组件
                    if (data.code!=0){
                        Notice_3(data.msg);
                    }else if (data.code==0){
                        //跳转到首页
                        location.href=ctx+'/index/home';
                    }
                }
            })
        }

});